/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Class;

import java.sql.*;
/**
 *
 * @author aissaroot
 */
public class Connect {
    private final String url="jdbc:mysql://localhost:3306/conge?zeroDateTimeBehavior=convertToNull"; // le lien pour connecter à la base de donnée
    private final String user="root"; // nomd'utilisateur
    private final String pass="adminroot"; // mot de pass
    private final String urldriver="com.mysql.jdbc.Driver"; // acceder au driver ojdbc7.jar
    private Connection con;
    
    public Connect(){
    try{
    Class.forName(urldriver);
    }catch(Exception ex){
    System.out.println("erreur : au niveau du lien de driver ");
    System.out.println(ex);
    }
    try{
    con=DriverManager.getConnection(url,user,pass);
    }catch(Exception ex){
    System.out.println("erreur : au niveau de getconnection ");
    System.out.println(ex);
    }
   }
    public Connection get_connect(){
    return con;
   }
    // method pour executer des requetes de type select
    public ResultSet req_select(String req){
        Statement stat;
        ResultSet R = null;
        int cond;
        try{
        stat=con.createStatement();
        R=stat.executeQuery(req);
        cond=1;
        }catch(SQLException ex){
        System.out.println(ex);
        cond=0;
        }
        if(cond==1){
        return R;
        }else{
        return null;
        }
    }
    // method pour executer des requetes de type insert , update , delete
    public int req_execute(String req)
    {
        Statement Stat;

        try{
        Stat=con.createStatement();
        Stat.executeUpdate(req);
        System.out.println("bien");
        return 1;
        }catch(SQLException ex){
        System.out.println("nonnnn");
        System.out.println(ex);
        return 0;
        }
    
     }
}
